<template>
    <div>
      <table>

      <tr>
        <td>上传头像：</td>
        <!--<td><input type="file" @change="submit">-->
        <td><input type="file">

        </td>
        <td>
          <button @onclick="submit"></button>
          <button @submit="submit">提交</button>
        </td>
      </tr>
      </table>

    </div>
</template>

<script>
    export default {
        name: "upload",
      data:function () {
        return{
          src:'',
        }
      },
      methods:{
          submit:function (e) {
            //获取文件
            let file = e.target.files[0];
            //声明表单参数
            let param = new FormData();

            param.append('file',file,file.name);

            //声明请求头
            let config = {headers:{'Content-Type':'multipart/form-data'}};

            //发送请求
            this.axios.post('http://127.0.0.1:8000/upload/',param,config).then((res)=>{
              console.log(res);
              this.src = 'http://127.0.0.1:8000/static/upload/'+res.data.filename;
            })

          }
      }
    }
</script>

<style scoped>

</style>
